﻿using Microsoft.AspNet.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ChartMonitor.Controllers
{
    public class ServerHub : Hub
    {
        static Queue<int>  result = new Queue<int>();//温度队列
        static Queue<int> result1 = new Queue<int>();//压力队列
        public void SendMsg(string message)
        {
            var rand = new Random();
            if (result.Count == 0)
            {
                
                for (int i = 0; i < 11; i++)
                {
                    result.Enqueue(rand.Next(10));
                    result1.Enqueue(rand.Next(10));
                }
            }
            else
            {
                //先添加，然后删除一个
                result.Enqueue(rand.Next(10));
                result.Dequeue();

                //先添加，然后删除一个
                result1.Enqueue(rand.Next(10));
                result1.Dequeue();
            }
            //result.ToList().ForEach(f =>
            //{
            //    System.Diagnostics.Debug.Write(f + ",");
            //});
            //System.Diagnostics.Debug.WriteLine("=======================================");
            //调用所有客户端的sendMessage方法(sendMessage有2个参数)  
            List<Queue<int>> resData = new List<Queue<int>>();
            resData.Add(result);
            resData.Add(result1);
            Clients.All.sendMessage(resData, message);
        }
    }
}